home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / patches / pgs3g1.lha / 3.0gUpdate / Macros.LHA / FontSpec.rexx next >
OS/2 REXX Batch file  |  1995-03-24  |  16KB  |  558 lines

  1. /* $VER: FontSpec.rexx 2.0 (24.03.94)
  2.    Copyright 1995 Soft-Logik Publishing Corporation
  3.    May not be distributed without Soft-Logik Publishing Corporation's express written permission */
  4.  
  5. OPTIONS RESULTS
  6. TRACE OFF
  7.  
  8. /* Make sure rexx support is opened */
  9. IF ~SHOW('L','rexxsupport.library') THEN
  10.    CALL ADDLIB('rexxsupport.library',0,-30)
  11.  
  12. ADDRESS 'PAGESTREAM'
  13.  
  14. /* DEFINES      */
  15.     pfontcount=0
  16.     totalfonts=0
  17.     cancel=9
  18. /* specsize   */
  19.     big=0
  20.     small=1
  21. /* whichfonts */
  22.     all=0
  23.     select=1
  24.  
  25. /* MAIN LOOP  */
  26. choice=INSTRUCT()                                /* find out what to print */
  27. if choice~=cancel then do
  28.         call FINDFONTS()
  29.         call SORTIFONTS()
  30.         if whichfonts=select then call CHOOSEFONTS() /* choose which fonts to print */
  31.         else do
  32.             do i=1 to ifontcount
  33.                 pfonts.i=ifonts.i
  34.             end
  35.             pfontcount=ifontcount
  36.         end
  37.         call CREATEDOC()                         /* create the document      */
  38.         if specsize=small then call SMALLSPEC()  /* layout 6 fonts per page  */
  39.         else call BIGSPEC()                      /* layout 1 font per page     */
  40.         call PRINTFONTS()
  41. end
  42. EXIT
  43.  
  44. INSTRUCT:
  45. /* GIVE INSTRUCTIONS */
  46.     allocarexxlist
  47.         hSpecSizeList=result
  48.     addarexxlist hSpecSizeList '"One font per page"'
  49.     addarexxlist hSpecSizeList '"Six fonts per page"'
  50.     allocarexxlist
  51.         hWhichFontsList=result
  52.     addarexxlist hWhichFontsList '"All fonts"'
  53.     addarexxlist hWhichFontsList '"Selected fonts"'
  54.  
  55.     allocarexxrequester '"Create Font Specimen Sheets"' 552 109
  56.         hInstructReq=result
  57.     addarexxgadget hInstructReq EXIT 12 92 70 label "_Print"
  58.         hPrintGadget=result
  59.     addarexxgadget hInstructReq EXIT 470 92 70 label "_Cancel"
  60.         hCancelGadget=result
  61.     addarexxgadget hInstructReq TEXT 8 10 536 border none string "'This macro will print font specimen sheets to help select fonts to'"
  62.     addarexxgadget hInstructReq TEXT 8 20 536 border none string "'use. You can choose to print detailed specimens with one font per'"
  63.     addarexxgadget hInstructReq TEXT 8 30 536 border none string "'page or small specimens with 6 fonts per page. You can also choose'"
  64.     addarexxgadget hInstructReq TEXT 8 40 536 border none string "'to print All installed fonts or Selected fonts only.'"
  65.     addarexxgadget hInstructReq CYCLE 12 64 240 label '"_Number"' labelpos left
  66.         hSpecSizeGadget=result
  67.     addarexxgadget hInstructReq CYCLE 292 64 248 label '"_Which fonts"' labelpos left
  68.         hWhichFontsGadget=result
  69.     setarexxgadget hInstructReq hSpecSizeGadget list hSpecSizeList current 0
  70.     setarexxgadget hInstructReq hWhichFontsGadget list hWhichFontsList current 0
  71.  
  72.     doarexxrequester hInstructReq
  73.         action=result
  74.     if action=hCancelGadget then RETURN cancel
  75.  
  76.     getarexxgadget hInstructReq hSpecSizeGadget current
  77.         specsize=result
  78.     getarexxgadget hInstructReq hWhichFontsGadget current
  79.         whichfonts=result
  80.  
  81.     freearexxrequester hInstructReq
  82.     freearexxlist hInstalledFontsList
  83.     freearexxlist hPrintFontsList
  84. RETURN 0
  85.  
  86. FINDFONTS:
  87. /* GET THE NAMES AND NUMBER OF FACES */
  88.     getfontfamilies ifonts
  89.     ifontcount=result
  90.  
  91.     /* Count Fonts */
  92.     fontcount=0
  93.     do i=0 to ifontcount-1
  94.         getfontstyles ifonts.i styles
  95.         stylecount=result
  96.         /* Repeat for each style */
  97.         do ii=0 to stylecount-1
  98.             fontcount=fontcount+1
  99.         end ii
  100.     end i
  101.     /* Shuffle 0 to end to work with sort routine */
  102.     ifonts.ifontcount=ifonts.0
  103. RETURN
  104.  
  105. SORTIFONTS:
  106. /* SORT THE LIST ALPHABETICALLY */
  107.     DO tick = 1 to ifontcount-1
  108.         nexttick=tick+1
  109.         IF ifonts.tick > ifonts.nexttick THEN DO
  110.             store=ifonts.nexttick
  111.             ifonts.nexttick=ifonts.tick
  112.             DO bubpos = tick-1 to 1 by -1 WHILE (store < ifonts.bubpos)
  113.                 nexttick=bubpos+1
  114.                 ifonts.nexttick = ifonts.bubpos
  115.             END bubpos
  116.             bubpos=bubpos+1
  117.             ifonts.bubpos=store
  118.         END
  119.     END tick
  120. RETURN
  121.  
  122. SORTPFONTS:
  123. /* SORT THE LIST ALPHABETICALLY */
  124.         DO tick = 1 to pfontcount-1
  125.         nexttick=tick+1
  126.         IF pfonts.tick > pfonts.nexttick THEN DO
  127.             store=pfonts.nexttick
  128.             pfonts.nexttick=pfonts.tick
  129.             DO bubpos = tick-1 to 1 by -1 WHILE (store < pfonts.bubpos)
  130.                 nexttick=bubpos+1
  131.                 pfonts.nexttick = pfonts.bubpos
  132.             END bubpos
  133.             bubpos=bubpos+1
  134.             pfonts.bubpos=store
  135.         END
  136.     END tick
  137. RETURN
  138.  
  139. CHOOSEFONTS:
  140. /* FIND OUT WHICH FONTS TO PRINT */
  141.  
  142.     call alloclists()
  143.  
  144.     /* Initialize the installed font list */
  145.     do i=1 to ifontcount
  146.     'getfontstyles "'ifonts.i'" 'styles
  147.         stylecount=result
  148.         'addarexxlist 'hInstalledFontsList' "'ifonts.i'"'
  149.     end i
  150.  
  151.         /* Allocate and build the requester */
  152.         allocarexxrequester '"Create Font Specimen Sheets"' 528 201
  153.             hChooseReq=result
  154.         addarexxgadget hChooseReq TEXT 8 10 250 border none string "'Select the typefaces to print:'" highdata true
  155.         addarexxgadget hChooseReq EXIT 12 184 70 label "_Print"
  156.             hPrintGadget=result
  157.         addarexxgadget hChooseReq EXIT 224 42 80 label '"_Add     ->"'
  158.             hAddGadget=result
  159.         addarexxgadget hChooseReq EXIT 224 62 80 label '"_Remove <-"'
  160.             hRemoveGadget=result
  161.         addarexxgadget hChooseReq EXIT 446 184 70 label "_Cancel"
  162.             hCancelGadget=result
  163.         addarexxgadget hChooseReq SCROLLIST 12 32 200 139 label '"Installed Typefaces"' labelpos aboveleft
  164.             hInstalledFontsGadget=result
  165.         addarexxgadget hChooseReq SCROLLIST 316 32 200 139 label '"Typefaces to Print"' labelpos aboveleft
  166.             hPrintFontsGadget=result
  167.  
  168.     /* FONT SELECTION LOOP */
  169.     exitflag=0
  170.     do until exitflag=1
  171.  
  172.         /* Do the font selection requester */
  173.         setarexxgadget hChooseReq hInstalledFontsGadget list hInstalledFontsList current 0
  174.         setarexxgadget hChooseReq hPrintFontsGadget list hPrintFontsList current 0
  175.         doarexxrequester hChooseReq
  176.             action=result
  177.  
  178.         select
  179.             when action=hCancelGadget then do      /* THE USER CANCELLED   */
  180.                 call freelists()
  181.                 retvalue=9
  182.                 exitflag=1
  183.                 end
  184.             when action=hPrintGadget then do      /* PRINT THE FONTS!     */
  185.                 call freelists()
  186.                 retvalue=1
  187.                 exitflag=1
  188.                 end
  189.             when action=hAddGadget then do          /* ADD A FONT TO PRINT  */
  190.                 getarexxgadget hChooseReq hInstalledFontsGadget current
  191.                 cfont=result+1
  192.                 pfontcount=pfontcount+1
  193.                 pfonts.pfontcount=ifonts.cfont
  194.                 call sortpfonts()                  /* sort the to print list  */
  195.                 call freelists()                  /* free the arexx lists    */
  196.                 call alloclists()                  /* alloc the lists again   */
  197.                 do i=1 to pfontcount              /* fill the to print list  */
  198.                     'addarexxlist 'hPrintFontsList' "'pfonts.i'"'
  199.                 end i
  200.                 do i=cfont to ifontcount          /* remove from ifonts      */
  201.                     nexti=i+1
  202.                     ifonts.i=ifonts.nexti
  203.                 end
  204.                 ifontcount=ifontcount-1
  205.                 do i=1 to ifontcount              /* fill the installed list */
  206.                     'addarexxlist 'hInstalledFontsList' "'ifonts.i'"'
  207.                 end i
  208.                 end
  209.             when action=hRemoveGadget then do       /* REMOVE A FONT TO PRINT */
  210.                 getarexxgadget hChooseReq hPrintFontsGadget current
  211.                 cfont=result+1
  212.                 ifontcount=ifontcount+1
  213.                 ifonts.ifontcount=pfonts.cfont
  214.                 call sortifonts()                  /* sort the installed list */
  215.                 call freelists()                  /* free the arexx lists    */
  216.                 call alloclists()                  /* alloc the lists again   */
  217.                 do i=1 to ifontcount              /* fill the installed list */
  218.                     'addarexxlist 'hInstalledFontsList' "'ifonts.i'"'
  219.                 end i
  220.                 do i=cfont to pfontcount          /* remove from pfonts      */
  221.                     nexti=i+1
  222.                     pfonts.i=pfonts.nexti
  223.                 end
  224.                 pfontcount=pfontcount-1
  225.                 do i=1 to pfontcount              /* fill the to print list  */
  226.                     'addarexxlist 'hPrintFontsList' "'pfonts.i'"'
  227.                 end i
  228.                 end
  229.         end
  230.     end
  231.     freearexxrequester hChooseReq
  232.  
  233.     if retvalue=9 then EXIT
  234.     if retvalue=1 & pfontcount=0 then do
  235.         call doalert("No fonts selected to print!")
  236.         EXIT
  237.     end
  238.  
  239. RETURN
  240.  
  241. ALLOCLISTS:
  242. /* Allocate lists for the installed fonts and the fonts to print */
  243.     allocarexxlist
  244.         hInstalledFontsList=result     /* list of installed fonts */
  245.     allocarexxlist
  246.         hPrintFontsList=result         /* list of fonts to print */
  247. RETURN
  248.  
  249. FREELISTS:
  250. /* Free lists for the installed fonts and the fonts to print */
  251.     freearexxlist hInstalledFontsList
  252.     freearexxlist hPrintFontsList
  253. RETURN
  254.  
  255.  
  256. CREATEDOC:
  257. /* Make the FontSpec document */
  258.     'newdocument FontSpec '
  259.     'setdocumentdesc "" '
  260.     'newmasterpage "Default Master Page" 8.5i 11i portrait single'
  261.     'setmasterpagedesc ""'
  262.     'setdimensions 8.5i 11i portrait single'
  263.     'setbleed 0i 0i '
  264.     'setmarginguides 0.5i 0.5i 1i 1i '
  265.     'setcolumnguides 1 0.25i '
  266.     'setdocumentstatus unchanged '
  267.     'openwindow View.1 page 1 '
  268. RETURN
  269.  
  270. SMALLSPEC:
  271. /* CREATE A MULTIPLE FONT SPECIMEN SHEET */
  272.  
  273.     'settoolmode text'       /* this ensures that no stray size handles get left around */
  274.  
  275.     openbusyrequester message "'Preparing FontSpec document...'" thermometer enabled abort enabled total 100 current 0
  276.         brhandle=result
  277.  
  278.     /* Make the style tags */
  279.     'newstyletag "FontSample1" character'
  280.     'newstyletag "FontSample2" character'
  281.     'newstyletag "FontSample3" character'
  282.     'newstyletag "FontSample4" character'
  283.     'newstyletag "FontSample5" character'
  284.     'newstyletag "FontSample6" character'
  285.  
  286.     /* Document Layout Loop */
  287.     do i=1 to 6
  288.         k=i+(i-1)*0.5       /* this gives us the correct offset */
  289.  
  290.         /* Draw the surrounding boxes */
  291.         'drawbox 0.5i 'k'i 8i 'k+1.25'i'
  292.  
  293.         /* Make the titles */
  294.         'drawtextobj 0.625i 'k+0.0625'i'
  295.             tohandle.i=result
  296.         'selecttext at 0.625i 'k+0.0625'i'
  297.         'settypesize 18pt'
  298.         'setfont Triumvirate'
  299.         'settypestyle Bold'
  300.         'insert "Font Name"'
  301.  
  302.         /* Make the text frames */
  303.         'drawcolumn 0.625i 'k+0.375'i 7.875i 'k+1.125'i columns 1 gutter 0'
  304.             sfhandle.i=result
  305.         'selecttext at 0.625i 'k+0.375'i'
  306.         if i=1 then do
  307.             'insert '||xrange('a','z')
  308.             'insertcontrol newparagraph'
  309.             'insert '||xrange('A','Z')
  310.             'insertcontrol newparagraph'
  311.             'insert 1234567890!@#$%^&*<?>«»'
  312.             'insertchar unicode 39'
  313.             'insertchar unicode 34'
  314.             'insertchar opendblquote'
  315.             'insertchar closedblquote'
  316.             'insertchar opensnglquote'
  317.             'insertchar closesnglquote'
  318.             'insertchar r c tm'
  319.             'selecttext all'
  320.             'copytext nostatus'
  321.             'setcharacterstyle "FontSample1"'
  322.             'settypesize 15pt'
  323.             'settracking 15%'
  324.             'selecttext none'
  325.             end
  326.         else do
  327.             'pastetext nostatus'
  328.             'setcharacterstyle FontSample'i
  329.             'settypesize 15pt'
  330.             'settracking 15%'
  331.             'selecttext none'
  332.         end
  333.  
  334.     call setbusy(16.7*i)
  335.     end i
  336.  
  337.     'closebusyrequester 'brhandle
  338. RETURN
  339.  
  340. BIGSPEC:
  341. /* CREATE A FULL PAGE FONT SPECIMEN SHEET */
  342.     openbusyrequester message "'Preparing FontSpec document...'" thermometer enabled abort enabled total 100 current 0
  343.         brhandle=result
  344.  
  345.     /* Draw the surrounding box */
  346.     'drawbox 0.5i 1i 8i 10i'
  347.  
  348.     /* Make the style tag */
  349.     'newstyletag "FontSample" character'
  350.  
  351.     /* Make the title */
  352.     'settoolmode text'
  353.     'drawtextobj 0.75i 1.25i'
  354.         tohandle=result
  355.     'selecttext at 0.75i 1.25i'
  356.     'settypesize 36pt'
  357.     'setfont Triumvirate'
  358.     'settypestyle Bold'
  359.     'insert "Font Name"'
  360.  
  361.     call setbusy(5)
  362.  
  363.     sizes.1=10
  364.     sizes.2=12
  365.     sizes.3=15
  366.     sizes.4=18
  367.     sizes.5=24
  368.     sizes.6=36
  369.     sizes.7=48
  370.  
  371.     /* Make the text frames */
  372.     'drawcolumn 0.75i 2i 1.25i 4.75i columns 1 gutter 0'
  373.         sfhandle=result
  374.     'selecttext at 0.75i 2i'
  375.     'settypesize 10pt'
  376.     do i=1 to 7
  377.         'setleading fixed 'sizes.i+2'pt'
  378.         'insert 'sizes.i'pt'
  379.         'insertcontrol newparagraph'
  380.         call setbusy(5+4*i)
  381.     end i
  382.  
  383.     'drawcolumn 1.25i 2i 7.75i 4.75i columns 1 gutter 0'
  384.         tfhandle=result
  385.     'selecttext at 1.25i 2i'
  386.     'setcharacterstyle "FontSample"'
  387.     do i=1 to 7
  388.         'setleading fixed 'sizes.i+2'pt'
  389.         'settypesize 'sizes.i'pt'
  390.         'insert "The Quick Brown Fox"'
  391.         'insertcontrol newparagraph'
  392.         call setbusy(33+4*i)
  393.     end i
  394.  
  395.     'drawtextobj 0.75i 5i'
  396.     'selecttext at 0.75i 5i'
  397.     'settypesize 18pt'
  398.     'setfont Triumvirate'
  399.     'settypestyle Bold'
  400.     'insert "Character Set Sample"'
  401.  
  402.     call setbusy(66)
  403.  
  404.     'drawcolumn 0.75i 5.5i 7.75i 7.25i columns 1 gutter 0'
  405.         mfhandle=result
  406.     'selecttext at 0.75i 5.5i'
  407.     'setcharacterstyle "FontSample"'
  408.     'settypesize 24pt'
  409.     'insert '||xrange('a','z')
  410.     call setbusy(69)
  411.     'insertcontrol newparagraph'
  412.     'insert '||xrange('A','Z')
  413.     call setbusy(72)
  414.     'insertcontrol newparagraph'
  415.     'insert 1234567890!@#$%^&*<?>«»'
  416.     'insertchar opendblquote'
  417.     'insertchar closedblquote'
  418.     'insertchar opensnglquote'
  419.     'insertchar closesnglquote'
  420.     'insertchar r c tm'
  421.  
  422.     call setbusy(75)
  423.  
  424.     'drawtextobj 0.75i 7.5i'
  425.     'selecttext at 0.75i 7.5i'
  426.     'settypesize 18pt'
  427.     'setfont Triumvirate'
  428.     'settypestyle Bold'
  429.     'insert "Body Text Sample"'
  430.  
  431.     call setbusy(80)
  432.  
  433.     'drawcolumn 0.75i 8i 7.75i 9.75i columns 1 gutter 0'
  434.         bfhandle=result
  435.     'selecttext at 0.75i 8i'
  436.     'setcharacterstyle "FontSample"'
  437.     'settypesize 12pt'
  438.     'setleading fixed 14pt'
  439.     'insert "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of"'
  440.     call setbusy(87)
  441.     'insert " incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us,"'
  442.     call setbusy(94)
  443.     'insert " we had nothing before us, we were all going direct to Heaven, we were all going direct the other way."'
  444.     call setbusy(100)
  445.     'closebusyrequester 'brhandle
  446. RETURN
  447.  
  448.  
  449. PRINTFONTS:
  450. /* PRINT LOOP */
  451.     openbusyrequester message "'Creating Font Specimens...'" thermometer enabled abort enabled total fontcount current 0
  452.         brhandle=result
  453.  
  454.     /* Build one master stem variable from the fonts */
  455.     do i=1 to pfontcount
  456.  
  457.         /* Get the type styles for the font */
  458.         getfontstyles pfonts.i styles
  459.         stylecount=result
  460.  
  461.         /* Repeat for each type style */
  462.         do ii=0 to stylecount-1
  463.  
  464.             /* Fill the master stem variable */
  465.             totalfonts=totalfonts+1
  466.             mfonts.totalfonts=pfonts.i
  467.             mstyles.totalfonts=styles.ii
  468.  
  469.         end ii
  470.     end i
  471.  
  472.     /* Count the pages to print */
  473.     if specsize=small then do
  474.         pagecount=trunc(totalfonts/6)
  475.         lastpage=totalfonts/6-trunc(totalfonts/6)*6  /* how many fonts on the last page?  */
  476.         if lastpage>0 then pagecount=pagecount+1     /* add a page if there's a remainder */
  477.         end
  478.     else pagecount=totalfonts
  479.  
  480.     /* Repeat for each page to print */
  481.     j=0
  482.     do i=1 to pagecount
  483.         j=j+1
  484.  
  485.         if specsize=small then do            /* Layout for 6 to a page */
  486.             do ii=1 to 6
  487.                 k=ii+(ii-1)*0.5             /* this gives us the correct offset */
  488.                 /* Change the title(s) */
  489.                 'selecttext at 0.625i 'k+0.0625'i'
  490.                 'selecttext all'
  491.                 if lastpage>0 & i=pagecount & ii>lastpage then do
  492.                     'insert "' '"
  493.                     'selecttext at 0.625i 'k+0.375'i'
  494.                     'selecttext all'
  495.                     'insert "' '"
  496.                     end
  497.                 else do
  498.                     'insert "'mfonts.j'-'mstyles.j'"'
  499.                     /* Change the font and style */
  500.                     'refresh wait'
  501.                     'clearstyletag FontSample'.ii
  502.                     'setfont 'mfonts.j' styletag FontSample'ii
  503.                     'settypestyle 'mstyles.j' styletag FontSample'ii
  504.                     'refresh continue'
  505.                 end
  506.                 j=j+1
  507.             end ii
  508.             j=j-1
  509.             end
  510.         else do
  511.             /* Change the title(s) */
  512.             'selecttext at 0.75i 1.25i'
  513.             'selecttext all'
  514.             'insert "'mfonts.j'-'mstyles.j'"'
  515.  
  516.             /* Change the font and style */
  517.             'refresh wait'
  518.             'clearstyletag FontSample'
  519.             'setfont 'pfonts.i' styletag FontSample'
  520.             'settypestyle 'styles.ii' styletag FontSample'
  521.             'refresh continue'
  522.         end
  523.  
  524.         /* Print the font sample page */
  525.         call setbusy((i-.7)/pagecount*100)
  526.         'printdocument copies 1 page 1 sides both scale actual output grayscale printermarks off mirror off negative off'
  527.         call setbusy(i/pagecount*100)
  528.     end i
  529.  
  530.     'closebusyrequester 'brhandle
  531.     'closedocument force'
  532. RETURN
  533.  
  534. DOALERT:
  535. parse arg astring
  536. /* Display an alert requester */
  537.         allocarexxrequester '"Macro Alert"' 334 55
  538.             hAlertReq=result
  539.         addarexxgadget hAlertReq TEXT 8 12 268 border none string '"'astring'"'
  540.         addarexxgadget hAlertReq EXIT 252 38 70 label "_Exit"
  541.         doarexxrequester hAlertReq
  542.         freearexxrequester hAlertReq
  543. RETURN
  544.  
  545. SETBUSY:
  546.     parse arg value
  547.     ADDRESS PAGESTREAM
  548.     setbusyrequester brhandle current value
  549.     getbusyrequester brhandle
  550.     if result=1 then call CLEANUP(1)
  551.     ADDRESS COMMAND
  552. RETURN
  553.  
  554. CLEANUP:
  555.     'closebusyrequester 'brhandle
  556. /*      'closedocument force'*/
  557. EXIT
  558.